package videoconferencia

import grails.test.*

class MaterialTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }
	
	void testNotExists() {
		//mock Domain class
		mockDomain(Material)
		//registra classe para testar
		Material material = new Material(nome:"Data Show")
		material.save()
		
		Material encontrado = Material.findByNome("DataShow")
		
		assertEquals null, encontrado
	}
	
	void testExists() {
		//mock Domain class
		mockDomain(Material)
		//registra classe para testar
		Material material = new Material(nome:"Data Show")
		material.save()
		//busca classe registrada
		Material encontrado = Material.findByNome("Data Show")
		//verifica se encontrou igual
		assertEquals material, encontrado
	}

    void testCreate() {
		//mock Domain class
		mockDomain(Material)
		//cria um ponteiro vazio
		Material material = null
		//tenta localizar registro
		if(!Material.findByNome("Data Show")) {
			material = new Material(nome:"Data Show")
			material.save()
		}
		//verifica se encontrou igual
		assertEquals 1, material.id
    }
	
	void testUpdate() {
		//mock Domain class
		mockDomain(Material)
		Material material = new Material(nome:"DataShow")
		material.save()
		material = new Material(nome:"Notebook")
		material.save()
		
		Material m = Material.findByNome("DataShow")
		if(m.count()) {
			m.nome = "Data Show"
			m.save()
		}
		
		//verifica se encontrou igual
		assertEquals m.id, 1
		//verifica se alterou
		assertEquals "Data Show", m.nome
	}
	
	void testDelete() {
		//mock Domain class
		mockDomain(Material)
		Material material = new Material(nome:"DataShow")
		material.save()
		material = new Material(nome:"Notebook")
		material.save()
		//busca registro e deleta
		Material m = Material.findByNome("DataShow")
		if(m != null)
		{
			m.delete()
		}
		//busca registro e verifica se apagou
		Material mat = Material.findByNome("DataShow")
		assertEquals mat, null
		
	}
}
